import cv2
import numpy as np
from time import time

# img = cv2.imread('D:/python/opencv-processing/laiya.jpg')
# # 加权平均值（最佳）
# gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# print(img.shape)
# # 显示灰度图
# cv2.imshow('gray',gray)
# cv2.waitKey(0)

img = cv2.imread('D:/python/opencv-processing/laiya.jpg')
# 取出图像的高，宽，深度 depth（通道数量）
h, w, c = img.shape
start = time()
# 一个通道的灰度图
gray = np.zeros((h, w), dtype=np.uint8)

for i in range(h):
    for j in range(w):
        gray[i][j] = img[i][j][0]*0.11+ img[i][j][1]*0.59+img[i][j][2]*0.3

end = time()
print(end - start)

# 均值灰度化
cv2.imshow("gray", gray)
cv2.waitKey(0)